local sk__baiyue = fk.CreateSkill {

  name = "sk__baiyue",

  tags = {  },

}


sk__baiyue:addEffect(fk.EventPhaseStart, {
  name = "sk__baiyue",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__baiyue.name) and player.phase == Player.Finish then
      local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      if turn_event == nil then return end
      return #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.from and move.from ~= player then
            for _, info in ipairs(move.moveInfo) do
              if player.room:getCardArea(info.cardId) == Card.DiscardPile then
                return true
              end
            end
          end
        end
      end, Player.HistoryTurn) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for _, move in ipairs(e.data) do
        if move.from and move.from ~= player then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
    end, Player.HistoryTurn)
    cards, _ = room:askToChooseCardsAndChoice(player,{
      cards=cards,
      choices={
        "OK"
      },
      skill_name=sk__baiyue.name,
      prompt="#sk__baiyue-card",
    })
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, sk__baiyue.name, nil, true, player)
  end,
})

return sk__baiyue